package com.x.erp.service;

import com.x.erp.manage.UserManage;
import com.alibaba.dubbo.config.annotation.Service;
import com.x.erp.dao.UserDao;
import com.x.erp.model.User;
import com.x.erp.rpc.UserRpcService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.x.framework.exception.BusinessException;
import com.x.framework.exception.ExceptionCode;
import com.x.framework.service.BaseService;

import java.util.List;

@Component
@Service(interfaceName = "com.x.erp.rpc.UserRpcService", timeout = 60000)
public class UserService extends BaseService implements UserRpcService {

	@Autowired
	private UserDao userDao;

	@Autowired
	private UserManage userManage;

	@Override
	public List<User> selectUserList(User user) {
		try {
			return userDao.selectUserList(user);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0009, e);
		}
	}

	/**
	 *
	 * @param user
	 * @return 市场管理员及员工查询
	 */
	@Override
	public List<User> selectMarketUserList(User user) {
		try {
			return userDao.selectMarketUserList(user);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0009, e);
		}
	}


	@Override
	public User selectUserInfoById(User user) {
		try {
			return userDao.selectUserInfoById(user);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0009, e);
		}
	}

	@Override
	public int selectUserNum(User user) {
		try {
			return userDao.selectUserNum(user);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0009, e);
		}
	}

	@Override
	public int selectMarketUserNum(User user) {
		try {
			return userDao.selectMarketUserNum(user);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0009, e);
		}
	}

	@Override
	public User insertUser(User user) {
		try {
			return userManage.insertUser(user);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	@Override
	public Integer updateUser(User user) {
		try {
			return userManage.updateUser(user);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

}
